home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _utilities / utilities / 001 / _basicaof / Examples / !Wave3D / c / Wave3d
Text File  |  1994-01-23  |  3KB  |  79 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "kernel.h"
  4. #include "swis.h"
  5.  
  6. extern void blitlines(int screenadr, int lines);
  7. extern unsigned intsqr(unsigned);
  8. extern Sin[];
  9.  
  10. #define plot_pixel(x,y,color) ( ((char*)bank1) [x+320*y] = color)
  11. static screenbase, bank1, bank2;
  12. static E[54];
  13. /*==================================================================*/
  14. static void initialise(void)
  15. {
  16.         int i, count=0;
  17.         _kernel_swi_regs arm;
  18.         int block[]={ 148, 150, -1};
  19.         _kernel_swi(OS_WriteI + 22, &arm, &arm);
  20.         _kernel_swi(OS_WriteI + 15, &arm, &arm);        /* select mode 15 */
  21.         _kernel_swi(OS_WriteI + 22, &arm, &arm);
  22.         _kernel_swi(OS_WriteI + 13, &arm, &arm);        /* select mode 13 */
  23.         _kernel_swi(OS_RemoveCursors, &arm, &arm);
  24.         arm.r[0] = (int)block;
  25.         arm.r[1] = (int)block;
  26.         _kernel_swi(OS_ReadVduVariables, &arm, &arm);
  27.         screenbase  = bank1 = block[0];
  28.         bank2 = bank1 + 80*1024;
  29.         if (block[1] < 160*1024)
  30.         {
  31.                 fprintf(stderr, "At least 160k screen memory needed\n");
  32.                 exit(1);
  33.         }
  34.         for (i=400;i>=-400;i-=15)
  35.                 E[count++]=(1<<16)*1024/(1024-i);
  36. }
  37. /*==================================================================*/
  38. static void swap_screens(void)
  39. {
  40.         int temp;
  41.         _kernel_osbyte(19,0,0);
  42.         _kernel_osbyte(113, bank1==screenbase ? 1 : 2, 0);
  43.         temp  = bank1;
  44.         bank1 = bank2;
  45.         bank2 = temp;
  46. }
  47. /*==================================================================*/
  48. int main(void)
  49. {
  50.         int x,z,f,g,offset=0,count=0;
  51.         initialise();
  52.         while (!_kernel_escape_seen())
  53.         {
  54.                 for (x=-380; x<=380; x+=15)
  55.                 {
  56.                         f=-1500, g=1500,count=0;
  57.                         for (z=380; z>=-380; z-=15)
  58.                         {
  59.                                 int a,e,y;
  60.                                 e=E[count++];
  61.                                 a=offset+intsqr(x*x+z*z);
  62.                                 y=((40*Sin[a & 255])>>16) -400;
  63.                                 y=(y*e)>>16;
  64.                                 if (y>=f) f=y;
  65.                                 if (y<=g) g=y;
  66.                                 if (y==f || y==g)
  67.                                 {
  68.                                         y=(25-(y>>2));
  69.                                         plot_pixel( 160+((x*e)>>18), y, a>>5);
  70.                                 }
  71.                         }
  72.                 }
  73.                 swap_screens();
  74.                 blitlines( bank1 + 320*90, 120);
  75.                 offset+=7;
  76.         }
  77. }
  78. /*==================================================================*/
  79.